package Map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapTest02 {
    public static void main(String[] args) {
        Map<Integer,String> map= new HashMap<Integer, String>();
        map.put(1,"China");
        map.put(2,"japan");
    map.put(3,"Asia");
    map.put(4,"Lisa");
    //遍历方法,keySet
        Set Keys =map.keySet();
        for (Object k:Keys) {
            System.out.println(k);//获得所有的键
            System.out.println(map.get(k));//获得所有的值
        }
        //遍历方式2  values(); 获得值
  Collection<String> cs = map.values();
        for (String value:cs){
            System.out.println(value);//获得所有的值
        }
        //entrySet();键值对
        //Set集合存储的都是node  getKey(), getValue
      Set<Map.Entry<Integer,String>> entry  =map.entrySet();
        for (Map.Entry<Integer,String> e:entry) {
            System.out.println(e.getKey()+":"+e.getValue());//拿到的是键值对的对象
        }
    }
}
